package com.cntaiping.royal.bass.system.controller;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.cntaiping.royal.bass.system.common.DateUtil;
import com.cntaiping.royal.bass.system.service.RedisUtil;
import com.cntaiping.royal.bass.system.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.Date;
import java.util.List;

/**
 * Created by simon
 */
@Controller
@RequestMapping("springboot")
public class UserController {

    @Autowired
    private UserService userService;
    @Autowired
    private RedisUtil redisService;

    @RequestMapping(value = "/getUserByGet", method = RequestMethod.GET,produces="application/json;charset=UTF-8")
    @ResponseBody
    public JSON getUserByGet(@RequestParam(value = "userName") String userName){

        List users = userService.findUser();

        redisService.set("Test","world");

        System.out.println(redisService.get("Test"));

        System.out.print(DateUtil.dateToString(new Date()));
        JSONObject json = new JSONObject();
        json.put("data", users);

        return json;
    }

    @RequestMapping(value = "/getUserByPost", method = RequestMethod.POST)
    String getUserByPost(@RequestParam(value = "userName") String userName){
        return "Hello " + userName;
    }

    @RequestMapping(value = "/getUserByJson",method = RequestMethod.POST)
    String getUserByJson(@RequestBody String data){
        return "Json is " + data;
    }

    @RequestMapping(value = "/")
    String getUserByGet(){
        return "index";
    }

    @RequestMapping(value = "/sys")
    String getSysUserByGet(){
        return "sys/sysuser/list";
    }
}
